package com.qys.erp.controller;

import java.util.List;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.qys.erp.domain.Region;
import com.qys.erp.service.IRegionService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 库位Controller
 * 
 * @author qys
 * @date 2021-06-19
 */
@RestController
@RequestMapping("/erp/region")
public class RegionController extends BaseController
{
    @Autowired
    private IRegionService regionService;


    /**
     * 查询库位列表
     */
    @PreAuthorize("@ss.hasPermi('erp:region:list')")
    @GetMapping("/list")
    public AjaxResult list(Region region)
    {
        List<Region> list = regionService.selectRegionList(region);
        //System.out.println("======"+ list);
        return AjaxResult.success(list);
    }


    /**
     * 导出库位列表
     */
    @PreAuthorize("@ss.hasPermi('erp:region:export')")
    @Log(title = "库位", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Region region)
    {
        List<Region> list = regionService.selectRegionList(region);
        ExcelUtil<Region> util = new ExcelUtil<Region>(Region.class);
        return util.exportExcel(list, "库位数据");
    }

    /**
     * 获取库位详细信息
     */
    @PreAuthorize("@ss.hasPermi('erp:region:query')")
    @GetMapping(value = "/{regionId}")
    public AjaxResult getInfo(@PathVariable("regionId") Long regionId)
    {
        return AjaxResult.success(regionService.selectRegionById(regionId));
    }


    /**
     * 新增库位
     */
    @PreAuthorize("@ss.hasPermi('erp:region:add')")
    @Log(title = "库位", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Region region)
    {
        return toAjax(regionService.insertRegion(region));
    }

    /**
     * 修改库位
     */
    @PreAuthorize("@ss.hasPermi('erp:region:edit')")
    @Log(title = "库位", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Region region)
    {
        return toAjax(regionService.updateRegion(region));
    }

    /**
     * 删除库位
     */
    @PreAuthorize("@ss.hasPermi('erp:region:remove')")
    @Log(title = "库位", businessType = BusinessType.DELETE)
	@DeleteMapping("/{regionIds}")
    public AjaxResult remove(@PathVariable Long[] regionIds)
    {
        return toAjax(regionService.deleteRegionByIds(regionIds));
    }
}
